#pragma once

#include <iostream>
#include"Protocol.hpp"

class Calculator {
    public:
        Calculator() {}
        ~Calculator() {}
        Response Execute(const Request& request) 
        {
            Response response;
            switch(request.GetOp()){
                case '+':
                    response.SetResult(request.GetX() + request.GetY());
                    break;
                case '-':
                    response.SetResult(request.GetX() - request.GetY());
                    break;
                case '*':
                    response.SetResult(request.GetX() * request.GetY());
                    break;
                case '/':{
                    if(request.GetY() == 0){
                        response.SetCode(1);//1就是 /0
                    }
                    else{
                        response.SetResult(request.GetX() / request.GetY());
                    }
                }break;
                case '%':{
                    if(request.GetY() == 0){
                        response.SetCode(2);//2就是mod 0
                    }
                    else{
                        response.SetResult(request.GetX() % request.GetY());
                    }
                }break;
                default:
                    response.SetCode(3);//3就是不支持的运算符
                    break;
            }
            return response;
        }

};